﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcShop.Models.Repositories;
using MvcShop.Models.ViewDataModels;

namespace MvcShop.Models.Services
{
    public interface IHelperService
    {
        IEnumerable<DHelpList> GetDHelpList(int page, int pageSize);
    }

    public class HelperService : ServiceBase, IHelperService
    {
        #region IHelperService 成员

        public IEnumerable<DHelpList> GetDHelpList(int page, int pageSize)
        {
            var query= (from help in this.dataContext.Helpers
                       join helpCate in this.dataContext.HelpCategories
                       on help.CategoryId equals helpCate.HelpCategoryId
                       orderby help.HelperId descending
                       select new DHelpList{ CategoryId=help.CategoryId, 
                           CategoryName=helpCate.CategoryName,
                           HelperId=help.HelperId,
                           HelperName = help.HelperName
                       }).Skip((page - 1) * pageSize).Take(pageSize).ToList();

            return query;
        }

        #endregion
    }
}
